package com.luban.springboot8.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.luban.springboot8.dao.UserDao;
import com.luban.springboot8.pojo.User;

@RestController
public class UserController {

	@Autowired
	private UserDao userDao;
	
	/**
	 * 新增用户
	 */
	@RequestMapping(value="/addUser")
	public String addUser(User user) {
		userDao.save(user);
		return "ok";
	}
	
	/**
	 * 查询所有用户列表
	 */
	@RequestMapping(value="/userList")
	public List<User> userList() {
		return userDao.findAll();
	}
	
	/**
	 * 修改用户
	 */
	@RequestMapping(value="/updateUser")
	public String updateUser(User user) {
		userDao.save(user);
		return "ok";
	}
	/**
	 * 删除用户
	 */
	@RequestMapping(value="/deleteUser")
	public String deleteeUser(Integer id) {
		userDao.deleteById(id);
		return "ok";
	}
}
